package com.controller;

import com.entity.Employee;
import com.service.EmployeeService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Data
@Controller // 标识这是一个 bean
public class EmployeeController {
    // 表示层
    @Autowired // 自动装配
    private EmployeeService employeeService;  // 依赖接口

    // 按 id 查询一个员工
    public Employee selectOneEmployee(int id) {
        Employee employee = employeeService.selectEmployeeById(id);
        return employee;
    }

    // 新增一个员工
    public String insertOneEmployee(Employee employee) {
        Boolean aBoolean = employeeService.insertEmployee(employee);
        return aBoolean ? "新增成功" : "新增失败";
    }

    // 修改一个员工
    public String updateOneEmployee(Employee employee) {
        Boolean aBoolean = employeeService.updateEmployeeById(employee);
        return aBoolean ? "修改成功" : "修改失败";
    }

    // 按 id 删除一个员工
    public String deleteOneEmployee(int id) {
        Boolean aBoolean = employeeService.deleteEmployeeById(id);
        return aBoolean? "删除成功" : "删除失败";
    }
}
